<?php
namespace DAOZHEN\D;

include(dirname(dirname(dirname(__FILE__)))."/zhconfig/Config.php");
include(dirname(dirname(__FILE__))."/config.php");
include (ZH_PATH . DS . MANAGERFPATH . DS . "top1" . ZH);
?>
<div class="wap-container">
	<nav class="breadcrumb" style="background-color: #fff; padding: 0 24px">
		首页   <a class="btn btn-success radius f-r"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
<?php
$action=SafeRequest(getPGC("atcion"),0);
switch ($action) {
    case "save":
        save();
        break;
    case "add":
        add();
        break;
    case "del":
        del();
        break;
    default:
        main();
}
            
function main()
{
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }
?>
<article class="Hui-admin-content clearfix">
<div class="panel mt-20">
	<div class="panel-body">
		<div class="clearfix">
			<span class="f-l">
				<a href="javascript:;" onClick="location='?atcion=add';" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
			</span>
		</div>
	<div class="clearfix mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
            <tr class="text-c">
            <th>项目id</th>
                            <th>项目名称（如血常规）</th>
                            <th> 项目说明（如需空腹）</th>
                            <th>归属科室ID</th>
                            
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
<?php
    /*
    $rs=D("dz_examitems")->getLinkAll("*",true);
    $pages = $rs["rows"];
    */
    $classid="0";
    $rs1=new \DAOZHEN\D\Examitems();
    $datas=$rs1->getAllNum();
    $pages = $datas["num"];
	If($pages<=0)
	{
		$OutStr="<tr class=\"text-c\">";
		$OutStr=$OutStr."<td colspan=10>&nbsp;<font color=\"red\">暂无内容</font></td>";
		$OutStr=$OutStr."</tr></tbody>";
		echo $OutStr;
	}
	Else
	{
        $pa = new \ZHMVC\B\TOOL\ShowPages();
		$pa->pvar="pg";
        //$pa->setvar(array("classid" => $classid));
		$pa->set(20,$pages);
		$rs=new \DAOZHEN\D\Examitems();
		$datas=$rs->getPages($pa->limit());
		$rows=$rs->getRows();
		$rs=null;
		//print_r($datas);
	    for($i=0;$i<$rows;$i++)
	    {
	    	$data=$datas[$i];
  ?>
  <tr class="text-c">
    <td><?php echo $data['item_id']; ?></td>
                        <td><?php echo $data['item_name']; ?></td>
                        <td><?php echo $data['description']; ?></td>
                        <td><?php echo $data['dept_id']; ?></td>
                        
    <td class="taskOptions"><a href="?atcion=add&postid=<?php echo $data["id"]; ?>&pg=<?php echo $currentpg;?>">编辑</a> | <a href="?atcion=del&postid=<?php echo $data["id"]; ?>&pg=<?php echo $currentpg;?>" onclick="{if(confirm('确定删除吗?')){return true;}return false;}">删除</a></td>
  </tr>
<?php
}
?>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="10">&nbsp;<?php $pa -> output(0); ?></td>
        </tr>
    </tfoot>
<?php
}
?>
</table>
					</div>
				</div>
			</div>
</article>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . "foot1" . ZH);
?>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
<?php
}
            
function add()
{
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }
	$postid=SafeRequest(getPGC("postid"),0);
            
	if(($postid!="") && ($postid!="0"))
	{
		$rs=new \DAOZHEN\D\Examitems();
		$data=$rs->getOne($postid);
		$rows=$rs->getRows();
		If($rows!=0)
		{
            $ilistid=$postid;
		    
                    $item_id=$data['item_id'];
                    
                    $item_name=$data['item_name'];
                    
                    $description=$data['description'];
                    
                    $dept_id=$data['dept_id'];
                    
		}
		else
		{
            $ilistid="";
		    
                    $item_id='';
                    
                    $item_name='';
                    
                    $description='';
                    
                    $dept_id='';
                    
        }
	}
    else
    {
       $ilistid="";
	   
                    $item_id='';
                    
                    $item_name='';
                    
                    $description='';
                    
                    $dept_id='';
                    
    }
?>
<div class="panel">
	<div class="panel-body">
         <!-- 表单 -->
            <form name="PForm" id="PForm" method="post" action="?atcion=save&postid=<?php echo $postid; ?>&pg=<?php echo $currentpg;?>" class="form form-horizontal">
            
                                <div class="row clearfix">
                					<label class="form-label col-xs-4 col-sm-3">项目id：</label>
                					<div class="form-controls col-xs-8 col-sm-9">
                						<input type="text" id="item_id" name="item_id" class="input-text" placeholder=""
                                        value="<?php echo $item_id; ?>" />
                					</div>
                				</div>
                                 
                            <div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">项目名称（如血常规）：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<input type="text" id="item_name" name="item_name" class="input-text" placeholder=""
                                    value="<?php echo $item_name; ?>" />
            					</div>
            				</div>
                             
                            <div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3"> 项目说明（如需空腹）：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<textarea id="description" name="description" class="textarea" rows="6" placeholder=""><?php echo $description; ?></textarea>
            					</div>
            				</div>
                            
                                <div class="row clearfix">
                					<label class="form-label col-xs-4 col-sm-3">归属科室ID：</label>
                					<div class="form-controls col-xs-8 col-sm-9">
                						<input type="text" id="dept_id" name="dept_id" class="input-text" placeholder=""
                                        value="<?php echo $dept_id; ?>" />
                					</div>
                				</div>
                                 
            <div class="row clearfix">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					</div>
			</div>
            </form>
          <!-- 表单 -->
          </div>
    	</div>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . "foot1" . ZH);
?>
<script type="text/javascript">
</script>
</body>
</html>
<?php
}
            
function save()
{
	$postid=SafeRequest(getPGC("postid"),0);
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }  
    $item_id=SafeRequest(getPGC("item_id"),0);
$item_name=SafeRequest(getPGC("item_name"),0);
$description=SafeRequest(getPGC("description"),0);
$dept_id=SafeRequest(getPGC("dept_id"),0);

   
	if(($postid!="") && ($postid!="0"))
	{
		$rs=new \DAOZHEN\D\Examitems();
		$data=$rs->update($postid,$item_id,$item_name,$description,$dept_id);
        $ilistid=$postid;
	}
	Else
	{
		$rs=new \DAOZHEN\D\Examitems();
		$data=$rs->add($item_id,$item_name,$description,$dept_id);
        $ilistid=$rs->getLastId();
	}
    echo "<script>alert('更新成功');window.location.href='admin_examitems.php?pg=".$currentpg."';</script>"; 
?>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . "foot1" . ZH);
?>
<script type="text/javascript">
</script>
</body>
</html>
<?php
}

            
function del()
{
	$postid=SafeRequest(getPGC("postid"),0);
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    } 
	if(($postid!="") && ($postid!="0"))
	{
		$rs=new \DAOZHEN\D\Examitems();
		$rs->delete($postid);
		//echo "<script>alert('更新成功');window.location.href='admin_examitems.php?pg=".$currentpg."';</script>";
	}
    echo "<script>alert('更新成功');window.location.href='admin_examitems.php?pg=".$currentpg."';</script>";
    ?>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . "foot1" . ZH);
?>
<script type="text/javascript">
</script>
</body>
</html>
<?php
}
?>
